function money(){
    (function () {
        let con = document.querySelector("#container")
        // console.log(con);
    
        fetch("http://chst.vip:1234/api/getmoneyctrl")
            .then(body => body.json())
            .then(res => {
                let html1 = ""
                res.result.forEach(item => {
                    html1 += `
                            <ul productid=${item.productId}>
                                <li class="li_1">
                                    <a href="#">${item.productImg2}</a>
                                </li>
                                <li class="li_2">
                                    <h3>${item.productName}</h3>
                                    <p>${item.productFrom}|${item.productTime}</p>
                                    <span>${item.productComCount}</span>
                                </li>
                            </ul>
                        `
                })
                // console.log(html1);
                con.innerHTML = html1

    
                //获取div元素，注册点击事件
                let divs = [...con.children];
    
                divs.forEach(div => {
                    div.onclick = function () {
                        let productid = this.getAttribute("productid")
                        // console.log(productid);
    
                        //跳转当前详情页面
                        location.href = `../pages/moneyctrl2.html?productid=${productid}`
                    }
                })
                fn(a)

    
            })
            

            let a =1
            //封装获取a  
            function fn(a){
                fetch(`http://chst.vip:1234/api/getmoneyctrl?pageid=${a}`)
                .then(body=>body.json())
                .then(res=>{
                        $('#select').val(a)
                        let result= res.result;
                        let{result:thing}=res
                        let productId = thing.productId
                        // 页面元素个数
                        let totalCount = res.totalCount;
                        // console.log(totalCount);

                        
                           // 获得的页面总数
                        //    console.log(totalCount/10);
                           let math =Math.ceil(totalCount/10);
                            //    console.log(math);
                   
                   
                           // 动态获取的页面数
                           body=""
                           for (var i=1;i<=math;i++){
                            //    console.log(i);
                               body +=
                               `<option value="${i}">${i}/${math}</option>
                               `
                           }
                         $('#select').append(body)
                        
    

                        let html1 = ""
                        result.forEach(item=>{
                            html1 += `
                            <ul productid=${item.productId}>
                                <li class="li_1">
                                    <a href="#">${item.productImg2}</a>
                                </li>
                                <li class="li_2">
                                    <h3>${item.productName}</h3>
                                    <p>${item.productFrom}|${item.productTime}</p>
                                    <span>${item.productComCount}</span>
                                </li>
                            </ul>
                        `
                            
                        })
                        con.innerHTML=html1
    
                        if(a==1){
    
                            $('.btn1').prop('disabled',true).css({background:'#f5d9b6'})
                        }else if(a>1){
                        
                        $('.btn1').prop('disabled',false).css({background:'orange'})
                        }
                
                
                        if(a==math){
                        
                            $('.btn2').prop('disabled',true).css({background:'#f5d9b6'})
                        }else if(a<math){
                        
                        $('.btn2').prop('disabled',false).css({background:'orange'})
                        }
                })
            }

            //下一页
            $('.btn2').click(function(){
                a++
                //下一页
                fn(a)
            })
    
            $('.btn1').click(function(){
                a--
                //上一页
                 fn(a)
            })
    
            // 监听下拉框变化
            $('#select').change(function(){
                a = $('#select').val()
                fn(a)
    
            })
    })()
}



      

    